package com.zch.work.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zch.domain.Result;
import com.zch.entity.TbOperateMould;
import com.zch.utils.ExcelUtils;
import com.zch.work.mapper.TbMouldMapper;
import com.zch.work.mapper.TbProcessMapper;
import com.zch.work.service.TbOperateMouldService;
import com.zch.work.mapper.TbOperateMouldMapper;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* @author 28763
* @description 针对表【tb_operate_mould(作业要素划分维护表(操作-设备中间表))】的数据库操作Service实现
* @createDate 2023-10-30 19:57:14
*/
@Service
public class TbOperateMouldServiceImpl extends ServiceImpl<TbOperateMouldMapper, TbOperateMould>
    implements TbOperateMouldService{

    @Override
    public Result deletedByID(TbOperateMould tbOperateMould) {
        TbOperateMould operateMould = new TbOperateMould();
        operateMould.setId(tbOperateMould.getId());
        operateMould.setDeleted(1);
        boolean b = updateById(operateMould);
        return b?Result.SUCCESS():Result.FAILED(201,"删除失败");
    }

    @Override
    public Result addOperate(TbOperateMould tbOperateMould) {
        boolean save = save(tbOperateMould);
        return save?Result.SUCCESS():Result.FAILED(201,"添加失败");
    }

    @Override
    public Result updateAll(TbOperateMould tbOperateMould) {
        boolean b = updateById(tbOperateMould);
        return b?Result.SUCCESS():Result.FAILED(201,"修改失败");
    }

    @Override
    public void exports(HttpServletResponse response) {
        List<TbOperateMould> list = list();
        ExcelUtils.export(response,"作业要素划分维护表",list,TbOperateMould.class);
    }

    @Override
    public Result importJob(MultipartFile file) throws Exception {
        List<TbOperateMould> tbOperateMoulds = ExcelUtils.readMultipartFile(file, TbOperateMould.class);
        for (TbOperateMould tbOperateMould : tbOperateMoulds) {
            System.out.println(tbOperateMoulds);
            boolean save = save(tbOperateMould);
        }
        return Result.SUCCESS();
    }


}




